home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / msdos / mxmenu.zip / NAVYTIME.MNU < prev    next >
Text File  |  1993-06-09  |  6KB  |  275 lines

  1. Comment
  2. ==========================================================
  3.  
  4. This program is used to call the Navy atomic clock and set all
  5. your file servers to the correct time.
  6.  
  7. You need to set the ComPort to your modem port and the TimeOffset
  8. to match your time zone.
  9.  
  10.  5 - New York
  11.  6 - Chicago
  12.  7 - Denver
  13.  8 - San Francisco
  14.  
  15. You might have to change the phone number if you to deal with getting an
  16. outside line.
  17.  
  18. This program will set the time on all servers you are attached to and
  19. have Console Operator status. It will then try to log into all other
  20. servers and set the time.
  21.  
  22. To log into the other servers and set the time,you will need to create a
  23. dummy user called TIMESYNC and a password of SETTIME. Give this user no
  24. rights but make him a console operator. You can even restrict the login
  25. time to late at night when this program is run. MarxMenu will attempt to
  26. log into all not attached servers under this name and set the time.
  27. MarxMenu will detach as soon as the time is set.
  28.  
  29. =========================================================
  30. EndComment
  31.  
  32. var
  33.   NumberToDial
  34.   TimeOffset
  35.   StartTime
  36.  
  37. StandardIO
  38.  
  39. ;----- Set com port, number, and time offset to match your system.
  40.  
  41. ComPort = Com2
  42. NumberToDial = '9,1-202-653-0351'
  43. TimeOffSet = 6                     ;Offset for Central Standard Time
  44.  
  45. ;===================[ Start of main program ]======================
  46.  
  47. ComInitPort(1200,8,'N',1)        ;1200 baud access only
  48.  
  49. Writeln
  50. Writeln 'MarxMenu NavyTime'
  51. Writeln 'Copyright 1992-93 by Marc Perkel * All right reserved.'
  52. Writeln
  53. ExitCode = 1                     ;errorlevel 1=fail 0=success
  54. StartTime = Now
  55.  
  56. Writeln '==> Reseting Modem'
  57.  
  58. ComWrite 'ATZ' CR
  59. WaitFor 'OK'
  60. Writeln
  61.  
  62. Writeln '==> Sending Modem Init String'
  63.  
  64. ComWrite 'AT&Q0' CR       ;&Q0 puts modem in dumb mode allowing it to
  65. WaitFor 'OK'              ;connect faster to atomic clock and save $$$
  66. Writeln
  67.  
  68. Writeln '==> Calling Naval Atomic Clock'
  69.  
  70. ComWriteln 'ATD ' NumberToDial
  71.  
  72. repeat
  73.    CallClock
  74.    Wait 100
  75. until ComLastLine <> 'BUSY'
  76.  
  77. ComWatchCD
  78.  
  79. SetTime(GetTimeString)
  80. SetAllServers
  81. ExitCode = 0           ;success
  82. HangupAndExit
  83.  
  84. ;========================[ Procedures ]=============================
  85.  
  86. Procedure SetTime (UtcTime)
  87. var T DayOfYear DateSt TimeSt
  88.  
  89.    ;- First we pick out the date.
  90.  
  91.    DayOfYear = Value(Mid(UtcTime,7,3))
  92.    DateSt = DateString(TimeOf('01-01-' + Str(Year)) + (DayOfYear - 1 * SecondsInDay))
  93.  
  94.    ;- Then we pick out the time.
  95.  
  96.    TimeSt = Mid(UtcTime,11,6)
  97.    Insert(':',TimeSt,3)
  98.    Insert(':',TimeSt,6)
  99.  
  100.    T = TimeOf(DateSt + ' ' + TimeSt)
  101.    T = T - (TimeOffset - DaylightSavingsTime * 3600) + 1
  102.  
  103.    Writeln
  104.    Writeln
  105.    Writeln 'Setting WorkStation Clock ... ' DateString(T) ' ' TimeString(T)
  106.    Now = T
  107.    NovServerTime = T
  108.    SetServerTime(NovDefaultServer)
  109. EndProc
  110.  
  111.  
  112. Procedure SetAllServers
  113. var AttachedServers AllServers Server ThisServer
  114.  
  115.    ;- We set the clock on all servers are are attached to.
  116.  
  117.    ThisServer = NovDefaultServer
  118.    NovAttachedServers(AttachedServers)
  119.    SortArray(AttachedServers)
  120.  
  121.    Loop AttachedServers
  122.       Server = AttachedServers[LoopIndex]
  123.       if Server <> ThisServer
  124.          SetServerTime(Server)
  125.       endif
  126.    EndLoop
  127.  
  128.    NovServers(AllServers)
  129.    SortArray(AllServers)
  130.  
  131.    ;- We set the clock on all servers are are not attached to.
  132.  
  133.    Loop AllServers
  134.       Server = AllServers[LoopIndex]
  135.       if PosInSortedList(Server,AttachedServers) = 0    ;not attached
  136.          NovLogin(Server + '/TIMESYNC','SETTIME')
  137.          if NovResult = 0
  138.             SetServerTime(Server)
  139.             NovDetach(Server)
  140.          else
  141.             Writeln 'Login on Server ' Server ' failed!'
  142.          endif
  143.       endif
  144.    EndLoop
  145. EndProc
  146.  
  147.  
  148. Procedure SetServerTime (Server)
  149.    Write 'Setting Server ' Server ' Clock ... '
  150.    NovSetPreferredServer Server
  151.  
  152.    NovServerTime = Now
  153.    if NovResult = 0
  154.       Writeln DateString ' ' TimeString
  155.    else
  156.       Writeln 'Failed!'
  157.    endif
  158.  
  159.    NovSetPreferredServer ''
  160. EndProc
  161.  
  162.  
  163. Procedure GetTimeString
  164.    while True
  165.       CharLoop
  166.       if (length(ComLastLine) = 20) and (Right(ComLastLine,3) = 'UTC')
  167.  
  168.          ;- Hangup Modem
  169.  
  170.          ComDTR Off
  171.          Return ComLastLine
  172.       endif
  173.    endwhile
  174. EndProc
  175.  
  176.  
  177. Procedure TestAbort
  178.  
  179.    ;- ConCDAbort is set to True if Carrier drops.
  180.  
  181.    if ComCDAbort
  182.       Writeln '[Carrier Dropped]'
  183.       HangupAndExit
  184.    endif
  185.  
  186.    ;- 2 Minutes or I'm out of here
  187.  
  188.    if Now - StartTime > 120
  189.       Writeln
  190.       Writeln '==> Timeout Disconnect'
  191.       HangupAndExit
  192.    endif
  193.  
  194.    ;- ESC to Exit
  195.  
  196.    if not KbdReady then Return
  197.    LastKey = ReadKey
  198.    if LastKey = ESC then HangupAndExit
  199. EndProc
  200.  
  201.  
  202. Procedure CharLoop
  203.    TestAbort
  204.    if ComCharReady
  205.       Write ComReadChar
  206.    endif
  207. EndProc
  208.  
  209.  
  210. Procedure WaitFor (St)
  211.    ComLastLine = ''
  212.    while ComLastLine <> St
  213.       CharLoop
  214.    endwhile
  215.    Wait 20
  216. EndProc
  217.  
  218.  
  219. Procedure HangupAndExit
  220.    ComDTR Off
  221.    ComWatchCD Off
  222.    ComWriteln 'ATZ'
  223.    Wait 40
  224.    ExitMenu
  225. EndProc
  226.  
  227.  
  228. Procedure CallClock
  229.    while True
  230.       CharLoop
  231.  
  232.       if pos('CONNECT',ComLastLine) > 0
  233.          Return
  234.  
  235.       elseif ComCD
  236.          Return
  237.  
  238.       elseif ComLastLine = 'BUSY'
  239.          Return
  240.  
  241.       elseif ComLastLine = 'NO DIALTONE'
  242.          HangupAndExit
  243.  
  244.       elseif ComLastLine = 'NO CARRIER'
  245.          HangupAndExit
  246.  
  247.       endif
  248.    endwhile
  249. EndProc
  250.  
  251.  
  252. Procedure DaylightSavingsTime
  253. var B E
  254.  
  255.    ;- First Sunday in April
  256.  
  257.    B = TimeOf('04-01-' + Str(Year))
  258.    while DayOfWeekOf(B) <> 0
  259.       B = B + SecondsInDay
  260.    endwhile
  261.  
  262.    ;- Last Sunday in October
  263.  
  264.    E = TimeOf('10-31-' + Str(Year))
  265.    while DayOfWeekOf(E) <> 0
  266.       E = E - SecondsInDay
  267.    endwhile
  268.  
  269.    if Now Within(B,E)
  270.       Return 1
  271.    else
  272.       Return 0
  273.    endif
  274. EndProc
  275.